package com.steven.ourcontest.contest.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.steven.ourcontest.base.BaseViewModel
import com.steven.ourcontest.contest.api.ContestApi
import com.steven.ourcontest.contest.bean.MatchInfoRes
import com.steven.ourcontest.utils.plusAssign
import io.reactivex.Observable

class ContestViewModel : BaseViewModel() {

    private val _matchRecommendRes = MutableLiveData<MatchInfoRes?>()
    val matchRecommendRes: LiveData<MatchInfoRes?>
        get() = _matchRecommendRes

    private val _matchHistoryRecommendRes = MutableLiveData<MatchInfoRes?>()
    val matchHistoryRecommendRes: LiveData<MatchInfoRes?>
        get() = _matchHistoryRecommendRes

    private val _matchHotRecommendRes = MutableLiveData<MatchInfoRes?>()
    val matchHotRecommendRes: LiveData<MatchInfoRes?>
        get() = _matchHotRecommendRes

    fun queryMatch(){
        disposed += ContestApi.instance.queryMatch()
            .subscribe({
                _matchRecommendRes.value = it
            }, {
                _matchRecommendRes.value = null
                it.printStackTrace()
            })
    }

    fun searchHistory(){
        disposed += ContestApi.instance.searchHistory()
            .subscribe({
                _matchHistoryRecommendRes.value = it
            }, {
                _matchHistoryRecommendRes.value = null
                it.printStackTrace()
            })
    }

    fun searchTop10MatchRecent(){
        disposed += ContestApi.instance.searchTop10MatchRecent()
            .subscribe({
                _matchHotRecommendRes.value = it
            }, {
                _matchHotRecommendRes.value = null
                it.printStackTrace()
            })
    }
}